//
//  SAPrintReceipt.m
//  Saas
//
//  Created by 杨荣 on 2020/6/3.
//  Copyright © 2020 bing. All rights reserved.
//

#import "SAPrintReceipt.h"
#import "SAUserInfoTool.h"
#import "SAUserInfo.h"

@implementation SAPrintReceipt

- (ESCPrinter *)escPrinter {
    if (!_escPrinter) {
         _escPrinter = [[ESCPrinter alloc] init];
    }
    return _escPrinter;
}

- (NSMutableData *)writeData {
    if (!_writeData) {
        _writeData = [NSMutableData data];
    }
    return _writeData;
}

- (SAOverallSetting *)overallSetting {
    return [SAOverallSetting shareInstance];
}

- (SAUserInfo *)userInfoModel {
    SAUserInfo *userInfo = [SAUserInfoTool getModel];
    return userInfo;
}

// 获取显示的支付方式：（支付宝:xx, 微信:xx）
- (NSString *)getDisplayPayWay:(NSArray <SACommodityWarehousingdetailPayVOSModel *>*)payVOS {
    if (payVOS.count <= 0) {
        return nil;
    }
    NSArray *filter = [payVOS filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id  _Nullable evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
        SACommodityWarehousingdetailPayVOSModel *model = evaluatedObject;
        return [model.payPrice floatValue] != 0;
    }]];
    if (filter.count <= 0) {
        return nil;
    }
    
    NSString *str = @"(";
    for (SACommodityWarehousingdetailPayVOSModel *model in filter) {
        NSString *payTypeStr = @"";
        if ([model.payType isEqualToString:@"1"]) {
            payTypeStr = @"现";
        }else if ([model.payType isEqualToString:@"2"]) {
            payTypeStr = @"刷";
        }else if ([model.payType isEqualToString:@"3"]) {
            payTypeStr = @"汇";
        }else if ([model.payType isEqualToString:@"4"]) {
            payTypeStr = @"微";
        }else if ([model.payType isEqualToString:@"5"]) {
            payTypeStr = @"支";
        }else if ([model.payType isEqualToString:@"6"]) {
            payTypeStr = @"余";
        }else if ([model.payType isEqualToString:@"7"]) {
            payTypeStr = @"扫";
        }
        if (payTypeStr.length == 0) {
            continue;
        }
        NSString *payPriceStr = [NSString stringWithFormat:@"%.2f",model.payPrice.floatValue/100];// 有效位的金额
        NSString *pay = [NSString stringWithFormat:@"%@: %@%@",payTypeStr,payPriceStr,@"元"];
        
        
        str = [NSString stringWithFormat:@"%@%@,",str,pay];
    }
    str = [str substringWithRange:NSMakeRange(0, str.length-1)];
     str = [NSString stringWithFormat:@"%@)",str];
    
    return str;
}
@end
